FROM php:7.2-fpm-alpine

RUN sed -i 's/http:\/\/dl-cdn.alpinelinux.org/https:\/\/mirrors.cloud.tencent.com/g' /etc/apk/repositories

RUN apk add -u --no-cache tzdata \
 && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

COPY ssh/* /root/.ssh/
RUN chmod 400 /root/.ssh/id_rsa

RUN apk upgrade && \
    apk add --no-cache curl \
        curl-dev \
        autoconf \
        openssh \
        git \
        gcc \
        make \
        g++ \
        vim \
        zlib-dev \
        nginx \
        graphviz \
        supervisor \
        libpng-dev \
        libpq \
        icu-dev \
        libffi-dev \
        freetype-dev \
        libxslt-dev \
        libjpeg-turbo-dev \
        libwebp-dev \
        libmemcached-dev \
        libmcrypt-dev \
        libzip-dev \
        npm \
        bash \
        librdkafka-dev && \
    docker-php-ext-configure gd \
      --with-gd \
      --with-freetype-dir=/usr/include/ \
      --with-png-dir=/usr/include/ \
      --with-jpeg-dir=/usr/include/ \
      --with-webp-dir=/usr/include/ && \
    docker-php-ext-install pdo_mysql mysqli gd exif intl xsl soap zip opcache sockets bcmath pcntl && \
    docker-php-source delete

COPY composer /usr/local/bin/

RUN composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ \
    && composer global require hirak/prestissimo \
    && composer clearcache \
    && npm install pm2@4.2.3 -g \
    && npm install cnpm -g

RUN pecl install redis-5.0.2 memcached-3.1.4 rdkafka yaf-3.0.8 yar-2.0.5 mcrypt \
    && docker-php-ext-enable redis memcached rdkafka yaf yar mcrypt

RUN mkdir -p /run/nginx && mkdir -p /tmp/data
RUN mkdir /data && chown -R www-data:www-data /data && chown -R www-data:www-data /tmp/data

RUN wget https://storage.googleapis.com/downloads.webmproject.org/releases/webp/libwebp-1.1.0.tar.gz -O /tmp/libwebp-1.1.0.tar.gz \
    && tar -C /tmp -zxvf /tmp/libwebp-1.1.0.tar.gz \
    && cd /tmp/libwebp-1.1.0 \
    && ./configure --prefix=/usr/local/libwebp --enable-everything \
    && make && make install

RUN apk del autoconf gcc make g++ \
    && rm -fr /var/cache/apk/* /tmp/* /usr/share/man

WORKDIR /var/www/html

COPY php-config/php.ini "$PHP_INI_DIR"
COPY php-config/conf.d/docker-php-ext-yaf.ini "$PHP_INI_DIR"/conf.d/
COPY php-config/conf.d/docker-php-ext-yar.ini "$PHP_INI_DIR"/conf.d/
COPY php-config/php-fpm.conf /usr/local/etc/
COPY php-config/www.conf /usr/local/etc/php-fpm.d/
COPY conf/ /etc

EXPOSE 80 443
ENV TZ Asia/Shanghai

COPY docker-entrypoint.sh /usr/local/bin/

ENTRYPOINT ["docker-entrypoint.sh"]

CMD ["supervisord", "-n", "-c", "/etc/supervisord.conf"]

HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 CMD curl --fail http://localhost || exit 1  
